<?php

/**
 * Contains all methods that had something todo with the games scene
 * @author Baagoe
 */
class Scene extends XMap {
    
    //Constructer
    public function __construct($configFile = null, $xmlMap = null) {
        parent::__construct($configFile, $xmlMap);
        $this->load('sound');
    }
    
    //Creates the bagground sound
    public function createBgSound() {
        $bgSound = (isset($this->xmlMap->attributes()->bgSound) ? $this->xmlMap->attributes()->bgSound : false);
        if($bgSound != false) {
            $this->sound->loadBgSound($bgSound);
            foreach($this->sound->printSounds("objectSounds", "objectSoundFolder", true) as $sound) {
                echo $sound;
            }
        }
    }
    
    //Echoes the BG img to the map
    public function createBg() {
        $bgImg = $this->xmlMap->attributes()->bgImg;
        $bgPath = $this->folders['bgFolder']. $bgImg;
        if(!empty($bgImg)) {
            $html = "<img id='gameBg' src='$bgPath' width=800; height=600; style='position: absolute; z-index: -1; left: 0px; top: 0px;'/>";
            echo $html;   
        }
    }
    
    //Creates the point where the user start
    public function createSpawn() {
        $spawnPoint = $this->xmlMap->spawnPoints->spawnPoint[0];
        if(!empty($spawnPoint)) {
             $spawnPointX = $spawnPoint->attributes()->posX;
             $spawnPointY = $spawnPoint->attributes()->posY;
             $html = "<script type='text/javascript'>player.create($spawnPointX, $spawnPointY);</script>";
             echo $html;
        }
    }
    
    //Creates the different connections that the different maps
    public function createConnections() {
        $connections = $this->xmlMap->mapConnections->children();
        if(!empty($connections)) {
             $html = ''; // Declaring HTML variabel
            
             foreach($connections as $node) {
                $goToMap = $node->attributes()->goToMap;
                $posX = $node->attributes()->posX. "px";
                $posY = $node->attributes()->posY. "px";
                $width = $node->attributes()->width. "px";
                $height = $node->attributes()->height. "px";
                $border = $this->connectionSize['showBorder'];
                $spawnX = $node->attributes()->spawnX. "px";
                $spawnY = $node->attributes()->spawnY. "px";
            
                if(empty($width) && empty($height)) {
                    $width = $this->connectionSize['W']. "px";
                    $height = $this->connectionSize['H']. "px";
                }
            
                if($border == "true") {
                    $borderCss = "border: 1px solid black";
                } else {
                    $borderCss = " ";
                }
                $html .= "<div id='$goToMap' style='left: $posX; top: $posY; display: block; $borderCss; position: absolute; width: $width; height: $height; z-index: 100' class='colobject mapConnection trigger'></div>";
                $html .= "<div id='nextSpawn$goToMap' style='position: absolute; left: $spawnX; top: $spawnY; $borderCss; border-color: #fff; z-index: 100; width: 1px; height: 1px;'></div>";

            }
            $html = "<div id='mapConnectionPoints'>$html</div>";
            echo $html;
        }
    }
}

?>
